package com.wsm.kotlintest.activity

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.wsm.kotlintest.viewmodel.ui.UIController

@Suppress("UNCHECKED_CAST")
@SuppressLint("Registered")
abstract class BaseActivity<BINDING : ViewDataBinding, VM : ViewModel>(vM: Class<out ViewModel>) : AppCompatActivity(), UIController {

    private var viewModelReified: Class<out ViewModel>? = vM
    var binding: BINDING? = null
    var viewModel: VM? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, setLayout())
        viewModel = ViewModelProviders.of(this).get(viewModelReified!!) as VM
        inject()
        binding?.setLifecycleOwner(this)
        doSomething()
    }

}